<?php
namespace app\visitor\controller;

use app\company\service\DataService;
use library\Controller;
use think\Db;
use think\Validate;
/**
 * 访客管理面板
 * 
 * 
 */
class Visitorin extends Controller
{
	protected $view_table = 'view_new_app_meeting_info_copy_date';

	/**
	 * 访客管理面板(正访客人)
	 * @auth         true
	 * @throws       	hink\Exception
	 * @throws       	hink\exception\PDOException
	 * @HtttpRequest                              get|post
	 * @Author       GNLEON
	 * @Param
	 * @DateTime     2020-11-23T11:16:35+0800
	 * @LastTime     2020-11-23T11:16:35+0800
	 * @return       [type]                       [description]
	 */
	public function index(){
		$this->title = '访客管理';
 		$dbconf = $this->getconfig('vister_db');
 		$where = '';
 		$nowdaytime = strtotime(date('Y-m-d', time()));
 		//search 
 		$order = $this->request->param('order')?:'desc';
        $order_column = $this->request->param('order_column')?:'createtime';
        $order_str = $order_column.' '.$order;

		$this->_query(Db::connect($dbconf)->table($this->view_table))->where($where)
    	                                    ->where('appointment_status not in (2,3) and auditing = 1')
    	                                    ->where('app_visittime','between',[$nowdaytime,$nowdaytime+24*60*60])
    	                                    ->like('vister_name,vister_mobile')
    	                                    // ->equal('arrive_status')
    	                                    // ->where('deleteTime is null')
    	                                    // ->order('app_visittime desc')
											->order($order_str)
    	                                    ->page();

	}

	/**
	 * 访问详情
	 * @auth         true
	 * @throws       	hink\Exception
	 * @throws       	hink\exception\PDOException
	 * @HtttpRequest                              get|post
	 * @Author       GNLEON
	 * @Param
	 * @DateTime     2020-11-23T13:42:36+0800
	 * @LastTime     2020-11-23T13:42:36+0800
	 * @return       [type]                       [description]
	 */
	public function details(){

		$dbconf = $this->getconfig('vister_db');

		$user_id = $this->request->param('userid');
		$id = $this->request->param('id');
		$validate = Validate::make([
		    'user_id'  => 'require',
		    'id' => 'require'
		]);
		
		$data = [
		    'user_id'  => $user_id,
		    'id' => $id,
		];
		if (!$validate->check($data)) {
			$this->error('用户信息丢失');
		}
		$nowdaytime = strtotime(date('Y-m-d', time()));

		$vister_info = Db::connect($dbconf)->table('view_user')->where('id = '.$user_id)->find();

		$app_info = Db::connect($dbconf)->table($this->view_table)->where('id = '.$id)->find();

		$nowday_list = Db::connect($dbconf)->table($this->view_table)->where('companyid = '.$app_info['companyid'].' and vister_uid = '.$user_id)
											->where('app_visittime','between',[$nowdaytime,$nowdaytime+24*60*60])
											->limit(3)
											->select();

		$data = [
			'vis_uinfo'=>$vister_info,
			'list'=>$app_info,
			'nowday_list'=>$nowday_list,
		];

		$this->assign('data',$data);
		return $this->fetch();
		
	}
}